<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>订单列表显示</title>
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- DataTables -->
  <link rel="stylesheet" href="../../plugins/datatables/dataTables.bootstrap4.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../../dist/css/adminlte.min.css">
  <!-- Google Font: Source Sans Pro -->
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">		
		
		
	</head>
	<body> 
		
        <div class="card-body" id="table1">
        	
        	<input type="text" class="form-control" name="Sasid" id="Sasid" oninput="SelSassid()" placeholder="根据订单号查询订单" />
        	<br />
        	<table id="example2" class="table table-bordered table-hover">
		                <tr>
		                  <th>收件人姓名</th>
		                  <th>收件人联系方式</th>
		                  <th>总价</th>
		                  <th width="180">寄件地址</th>
		                  <th>收件地址</th>
		                  <th>寄件人姓名</th>
		                  <th>寄件人联系方式</th>
		                  <th>货物类型</th>
		                  <th width="150">操作</th>
		                </tr>
	                <tbody id="UserTable"></tbody>
          	</table>
        </div>
        
        <div id="table2">
			<center>
					<br />
					<table border="0" align="center" width="900" >
						
						<tr>
							<td colspan="6">
								<h3 align="left">寄件人信息</h3>
								<hr />							
							</td>
						</tr>
						
						<tr>
							<td align="right">
								<label for="exampleInputEmail1">姓名: &nbsp; &nbsp;</label>
							</td>
							<td width="240" height="60">
								<input type="text" class="form-control" name="senderinformation" id="senderinformation" style="width: 240px;" onblur="fun4()" placeholder="只能输入 7 以内的字符" />
							</td>
							<td><span id="div4"></span></td>
							<td align="right">
								<label for="exampleInputEmail1"><span style="color: #FF0000;">*&nbsp;</span>联系方式:&nbsp; &nbsp;</label>
							</td>
							<td width="240" height="60">
								<input type="text" class="form-control" name="sendercontactway" id="sendercontactway" oninput="fun1()" placeholder="请输入 6 位  或 11 位 联系方式" />
							</td>
							<td width="100">
								<div id="div1"></div>
							</td>
						</tr>
						<tr>
							<td align="right">
								<label for="exampleInputEmail1"><span style="color: #FF0000;">*&nbsp;</span>重量: &nbsp; &nbsp;</label>
							</td>
							<td width="240" height="60">
								<input type="text" class="form-control" name="weight" id="weight" placeholder="单位 (kg)" oninput="fun2()" />
							</td>
							<td width="80">
								<div id="div2"></div>
							</td>
							<td align="right">
								<label for="exampleInputEmail1">预计到达日期:&nbsp; &nbsp;</label>
							</td>
							<td width="240" height="60">
								<input type="date" class="form-control" name="required_date"  id="required_date" />
							</td>
							<td></td>
						</tr>
						<tr>
							<td align="right">
								<label for="exampleInputEmail1">寄件地址: &nbsp; &nbsp;</label>
							</td>
							<td width="240" height="60">
								<input type="text" class="form-control" name="cargoinformation" id="cargoinformation" style="width: 240px;" />
							</td>
							<td>&nbsp;</td>
							<td align="right">
								<label for="exampleInputEmail1">收件地址: &nbsp; &nbsp;</label>
							</td>
							<td width="240" height="60">
								<input type="text" class="form-control" name="placeofdeparture" id="placeofdeparture" oninput="searchByStationName();" />
							</td>
							<td></td>
						</tr>
					</table>
					
					
					<br />
					<table border="0" align="center" width="900" >
						<tr>
							<td colspan="6">
								<h3 align="left">收件人信息: &nbsp; &nbsp;</h3>
								<hr />							
							</td>
						</tr>
						<tr>
							<td align="right">
								<label for="exampleInputEmail1">姓名: &nbsp; &nbsp;</label>
							</td>
							<td width="240" height="60">
								<input type="text" class="form-control" name="consigneeinformation" id="consigneeinformation" onblur="fun5()" placeholder="只能输入 7 以内的字符" />
							</td>
							<td width="80"><span id="div5"></span></td>
							<td align="right" width="135">
								<label for="exampleInputEmail1"><span style="color: #FF0000;">*&nbsp;</span>联系方式: &nbsp; &nbsp;</label>
							</td>
							<td width="240" height="60">
								<input type="text" class="form-control" name="concontactway" id="concontactway" oninput="fun3()" placeholder="请输入 6 位  或 11 位 联系方式"/>
							</td>
							<td width="100">
								<div id="div3"></div>
							</td>
						</tr>
						<tr>
							<td colspan="2" align="center" >
								<br />
								<label for="exampleInputEmail1">总价:&nbsp; &nbsp;<span id="zhongjia"><span style='color: #FF0000;'>0&nbsp;元</span></span></label>
							</td>
							<td></td>
							<td align="right">
								<label for="exampleInputEmail1"><span style="color: #FF0000;">*&nbsp;</span>货物类型: &nbsp; &nbsp;</label>
							</td>
							<td>
								<input type="text" class="form-control" name="ordertype" id="ordertype"/>
							</td>
							<td></td>
						</tr>
					</table>
							<br /><br />
							<button type="button" class="btn btn-default" data-dismiss="modal" onclick="StopTable()" >返回</button>
							<button type="button" class="btn btn-primary" onclick="UpSendasing()" >修改订单</button>
							
			
			
			
			
			
			<!-- 地图  display: none; 隐藏状态   -->
			<div id="container" style="position: absolute;
				display: none;
	            margin-top:20px; 
	            width: 600px; 
	            height: 290px; 
	            top: 50; 
	            border: 1px solid gray;
	            overflow:hidden;">
			</div>	 
			</center>
        </div>
        

	
		
	 
		
	
	</body>
	
<!-- jQuery -->
<script src="../../plugins/jquery/jquery.min.js"></script>
<!-- 权限 js -->
<!--<script type="text/javascript" src="../../js/login.js" ></script>-->
<!-- Bootstrap 4 -->
<script src="../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables -->
<script src="../../plugins/datatables/jquery.dataTables.js"></script>
<script src="../../plugins/datatables/dataTables.bootstrap4.js"></script>
<!-- SlimScroll -->
<script src="../../plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="../../plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="../../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
<!-- 地图 -->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=Nsbrrt0AKiMM8QmTaQp4iLby9DtiSWSf"></script>
<!-- 自定义的 js 文件  -->
<script type="text/javascript" src="js/express.js"></script>



<script>
	
	
$(function(){
	//隐藏修改层
	$("#table2").hide();
	SelTable();
});	
	
	
	
// 表单的状态
var stat = true;
	
//经度 longitude  纬度 latitude
var longitude = 0; //经度
var latitude = 0;  //纬度
var totalvalue = 0; //总价
var sid = null;
	
//确认修改
function UpSendasing(){
	var	placeofdeparture = $("#placeofdeparture").val(); //收件地址 （向数据库添加 经度 longitude  纬度 latitude）
	var	sendercontactway = $("#sendercontactway").val(); //寄件人联系方式 ？
	var	concontactway  = $("#concontactway").val(); //收件人联系方式 ？
	var senderinformation = $("#senderinformation").val(); //寄件人信息 （姓名）
	
	var	cargoinformation = $("#cargoinformation").val(); //寄件地址 ？
	var	consigneeinformation =$("#consigneeinformation").val(); //收件人信息 （姓名）
	var	required_date = $("#required_date").val(); //预计到达日期
	var weight = $("#weight").val(); //重量
	var ordertype = $("#ordertype").val(); //货物类型
	
	if(placeofdeparture == "" || sendercontactway == "" || concontactway == "" || cargoinformation == "" || consigneeinformation == "" || required_date == "" || ordertype ==""){ //收件地址
		stat = false;
	}else{
		stat = true;
	}
	
	if(placeofdeparture != 0 && cargoinformation != 0){
	    if(stat == true){
			if(placeofdeparture == cargoinformation){
				alert("收件地址  和  寄件地址不能相同");
			}else{
		    	$.ajax({
					type:"post",
			    	url:"http://127.0.0.1:8075/UpSendasing",
			    	xhrFields:{withCredentials: true},
			    	crossDomain: true,
			    	dataType:"json",
			    	data:{"placeofdeparture":placeofdeparture,"sendercontactway":sendercontactway,"concontactway":concontactway,
			    	"cargoinformation":cargoinformation,"consigneeinformation":consigneeinformation,"required_date":required_date,
			    	"longitude":longitude,"latitude":latitude,"totalvalue":totalvalue,"senderinformation":senderinformation,"ordertype":ordertype,
			    	"sasid":sid},
			    	success:function(msg){
			    		if(msg != 0){
			    			location.reload();
			    		}else{
			    			alert("修改失败");
			    		}
			    	}
		    	});						
			}
	    }else{
	    	alert("请填写有效完整的数据");
	    }
	}else{
		alert("请填写有效完整的数据");
	}
	
}
	
	
//删除
function DelStaff(sasid){
	
	if(confirm("确定删除吗")){
	    $.ajax({
	    	type:"post",
	    	url:"http://127.0.0.1:8075/DelSend",
	    	xhrFields:{withCredentials: true},
	    	crossDomain: true,
	    	dataType:"json",
	    	data:{"sasid":sasid},
	    	success:function(msg){
	    		if(msg !=0 ){alert("删除成功!");}
	    		location.reload();
	    	}
	    });
		return true;
	}
	return false;
}
	
//点击修改
function UpdStaff(sasid){
	$("#table1").hide();
	$("#table2").show();
	$.ajax({
    	type:"post",
    	url:"http://127.0.0.1:8075/getbyidSend",
    	xhrFields:{withCredentials: true},
    	crossDomain: true,
    	dataType:"json",
    	data:{"sasid":sasid},
    	success:function(msg){
			$("#placeofdeparture").val(msg.placeofdeparture); //收件地址 （向数据库添加 经度 longitude  纬度 latitude）
			$("#sendercontactway").val(msg.sendercontactway); //寄件人联系方式 ？
			$("#concontactway").val(msg.concontactway); //收件人联系方式 ？
			$("#senderinformation").val(msg.senderinformation); //寄件人信息 （姓名）
			$("#cargoinformation").val(msg.cargoinformation); //寄件地址 ？
			$("#consigneeinformation").val(msg.consigneeinformation); //收件人信息 （姓名）
			$("#ordertype").val(msg.ordertype); //货物类型
			if(longitude == 0){longitude = msg.longitude;}
			if(latitude == 0){latitude = msg.latitude;}
			sid = sasid;
    	}
    });
}
	
//根据快递单号查询订单
function SelSassid(){
	var Sasid = $("#Sasid").val();
	//alert("根据id查询订单"+Sasid);
    $.ajax({
    	type:"post",
    	url:"http://127.0.0.1:8075/getbyidSend",
    	xhrFields:{withCredentials: true},
    	crossDomain: true,
    	dataType:"json",
    	data:{"sasid":Sasid},
    	success:function(n){
			//$("#UserTable")//alert(n.cargoinformation);
			$("#UserTable").empty();
			$("#UserTable").append("<tr>"+
                  "<td>"+n.consigneeinformation+"</td>"+
                  "<td>"+n.concontactway+"</td>"+
                  "<td>"+n.totalvalue+"</td>"+
                  "<td>"+n.cargoinformation+"</td>"+
                  "<td>"+n.placeofdeparture+"</td>"+
                  "<td>"+n.senderinformation+"</td>"+
                  "<td>"+n.sendercontactway+"</td>"+
                  "<td>"+n.ordertype+"</td>"+
                  "<td>"+
                  	"<button type='button' class='btn btn-primary' data-toggle='modal' id='adminDelete' onclick='DelStaff("+n.sasid+")'>删除</button>"+
                  	"&nbsp;&nbsp;"+
                  	"<button type='button' class='btn btn-primary' data-toggle='modal' data-target='.bs-example-modal-lg' onclick='UpdStaff("+n.sasid+")'>修改</button>"+
                  "</td>"+
                "</tr>");
                if(n == 0){$("#UserTable").empty();}
    	}
    });
	if(Sasid == ""){SelTable();}
}
	
	
//取消修改
function StopTable(){
	$("#table1").show();
	$("#table2").hide();
}
	

function SelTable(){
	    $.ajax({
	    	type:"post",
	    	url:"http://127.0.0.1:8075/SelSendasing",
	    	xhrFields:{withCredentials: true},
	    	crossDomain: true,
	    	dataType:"json",
	    	success:function(msg){
				$.each(msg,function(i, n){
					//$("#UserTable").empty();
	  				$("#UserTable").append("<tr>"+
		                  "<td>"+n.consigneeinformation+"</td>"+
		                  "<td>"+n.concontactway+"</td>"+
		                  "<td>"+n.totalvalue+"</td>"+
		                  "<td>"+n.cargoinformation+"</td>"+
		                  "<td>"+n.placeofdeparture+"</td>"+
		                  "<td>"+n.senderinformation+"</td>"+
		                  "<td>"+n.sendercontactway+"</td>"+
		                  "<td>"+n.ordertype+"</td>"+
		                  "<td>"+
		                  	"<button type='button' class='btn btn-primary' data-toggle='modal' id='adminDelete' onclick='DelStaff("+n.sasid+")'>删除</button>"+
		                  	"&nbsp;&nbsp;"+
		                  	"<button type='button' class='btn btn-primary' data-toggle='modal' data-target='.bs-example-modal-lg' onclick='UpdStaff("+n.sasid+")'>修改</button>"+
		                  "</td>"+
		                "</tr>");
				});
	    	}
	    });	
	
}

</script>





</html>
